<template>
    <div>
        <a-modal v-model="visible" title="添加好友" @ok="handleOk">
            <a-form-model :label-col="labelCol" :wrapper-col="wrapperCol" ref="ruleForm" :model="formData"
                :rules="rules">
                <a-form-model-item label="车识别码" prop="identificationCode">
                    <a-input v-model="formData.identificationCode" placeholder="请输入车识别码">
                    </a-input>
                </a-form-model-item>

            </a-form-model>
        </a-modal>
    </div>
</template>

<script>
import { httpAction } from '../../../api/manage';

export default {
    data() {
        return {
            labelCol: { span: 4 },
            wrapperCol: { span: 14 },
            visible: false,
            formData: {},
            rules: {
                identificationCode: [{ required: true, trigger: 'blur', message: '请输入车识别码' }],
            },
            url: {
                add: '/chat/nmcChatFriends/add'
            }
        };
    },
    methods: {
        showModal() {
            this.visible = true;
        },
        handleOk(e) {
            this.$refs.ruleForm.validate(valid => {
                if (valid) {
                    httpAction(this.url.add, this.formData, 'post').then(res => {
                        if (res.success) {
                            this.$message.success(res.message)
                            this.visible = false;
                            this.$emit('init')
                        } else {
                            this.$message.error(res.message)
                            this.visible = true;
                        }
                    })
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });


        },
    },
};
</script>

<style></style>